<template>
	<image src="/static/image/09.png" mode="widthFix" class="bg"></image>
	<u-navbar
	title="平台认证"
	:autoBack="true"
	:background="{
	background:'#E40417'
	}"
	:border-bottom="false"
	titleSize="28rpx" titleColor="#fff"
	back-icon-color="#fff"
	:titleBold="false"
	/>
	
	<view class="container pl30 pr30">
		<view class="mask t-flex center p30 bgf r20" v-if="data && disabled">
			<view class="c6 f30 bold" v-if="data.status==0">
				平台审核中...
			</view>
			<view class="c6 f30 bold t-flex center" v-if="data.status==1" style="color: #804101;">
				<uv-image src="/static/image/10.png" mode="aspectFit"
				width="40rpx"
				height="40rpx"
				></uv-image>
				<text class="ml20">已认证</text>
			</view>
			<view class="" v-if="data.status==2">
				<view class="mainC f30 bold">
					审核未通过，原因：{{data.remark}}
				</view>
				<view class="rebtn t-flex center mt20 mainBC cf f26 r20 pt10 pb10 pl30 pr30"
				@click="disabled = false"
				>重新编辑</view>
			</view>
		</view>
		<view class="box bgf pt30 pl10 pr10 r20 mt30">
			<view class="f32 c3 mb3 pb30 title bold ml20 mr20">
				认证信息
			</view>
			<forms :options="userform.options" v-model="userform.value" ref="userformsE" :disabled="disabled"></forms>
			
		</view>
		
		<view class="box bgf pt30 pl10 pr10 r20 mt30">
			<view class="f32 c3 mb3 pb30 title bold ml20 mr20">
				车辆信息
			</view>
			<forms :options="carform.options" v-model="carform.value" ref="carformsE" :disabled="disabled"></forms>
			
		</view>
		
		
		
		
	</view>
	
	<view class="bpad"></view>
	<view class="bpad"></view>
	<view class="Allbottom t-flex center safeArea" v-if="!disabled">
		<view class="btn t-flex center cf f30" @click="submit">提交</view>
	</view>
	
	
</template>

<script setup lang="ts">
	import { reactive, ref } from "vue"
	import { notEmpty } from "../../lib/ts/forms";
	import { applySf, sfRzInfo } from "../../api";
	import { showToast } from "../../lib/ts/util";
	import { useStore } from "../../store";
	
	const store = useStore()
	const carformsE = ref()
	const userformsE = ref()
	let data = ref()
	let disabled = ref(false)
	const getdata = async ()=>{
		let res = await sfRzInfo(store.userinfo.id)
		if(res){
			data.value = res
			disabled.value = true
			userform.value.name = res.name
			userform.value.idcard = res.idcard
			userform.value.sfz =[res.sfz_a_image,res.sfz_b_image]
			userform.value.jsz_a_image = [res.jsz_a_image]
			carform.value.car_number = res.car_number
			carform.value.car_type = res.car_type
			carform.value.fjs_a_image = res.fjs_a_image.split(',')
		}
	}
	getdata()
	
	let userform = reactive({
		options:[
			{name:'姓名',required:true,type:'text',rule:[notEmpty()],key:'name'},
			{name:'身份证号',required:true,type:'text',rule:[notEmpty()],key:'idcard'},
			{name:'身份证正反面',required:true,type:'idcard',rule:[notEmpty()],key:'sfz'},
			{name:'驾驶证',required:true,type:'images',rule:[notEmpty()],key:'jsz_a_image',max:1}
		],
		value:{}
	})
	
	
	let carform =  reactive({
		options:[
			{name:'车牌号',type:'text',key:'car_number'},
			{name:'车辆型号',type:'text',key:'car_type'},
			{name:'上传车辆外观照片',required:true,type:'images',rule:[notEmpty()],key:'fjs_a_image'}
		],
		value:{}
	})
	
	
	
	const submit = async ()=>{
		let formdata = {
			...userform.value,
			...carform.value,
			sfz_a_image:userform.value.sfz[1],
			sfz_b_image:userform.value.sfz[0],
			jsz_a_image:userform.value.jsz_a_image[0],
			fjs_a_image:carform.value.fjs_a_image.join(',')
		}
		
		let res = await applySf(formdata)
		showToast(res.msg)
		store.getUserinfo()
		getdata()
		
		
		
		
	}
	
	
	
	

</script>

<style scoped lang="scss">
	.bg{
		width: 100%;
		position: fixed;
	}
	
	.container{
		position: relative;
		z-index: 2;
	}
	
	.title{
		border-bottom: 1px solid #f6f6f6;
	}
	
	.mask{
		width: 100%;

	}
	
	
	
</style>
